home *** CD-ROM | disk | FTP | other *** search
/ Amiga Inside! / Amiga FD Inside (1995)(Ultramax).iso / berndspd / systemtools / xcrypt / xcrypt.asm < prev    next >
Encoding:
Assembly Source File  |  1994-01-26  |  10.1 KB  |  458 lines

  1. ;==============================  COPYRIGHT  ===============================
  2.  
  3. ;        Author:        Thorsten Hopf
  4.  
  5. ;        Program:    XCrypt - crypt/decrypt using XPK
  6. ;        Version:    V1.0
  7. ;        Date:        06/01/94
  8.  
  9. ;===============================  VERSION  ================================
  10.  
  11. PRGNAME        MACRO
  12.         dc.b " XCrypt "
  13.         ENDM
  14. VERSION        MACRO
  15.         dc.b "V1.0"
  16.         ENDM
  17. VersionDate:    MACRO
  18.         dc.b    ' (06.01.94)',0
  19.         ENDM
  20.  
  21. ;==========================  MACRO DEFINITIONS  ===========================
  22.  
  23. CALLSYS        MACRO
  24.         jsr _LVO\1(a6)
  25.         ENDM
  26.  
  27. ;=========================  INCLUDE DEFINITIONS  ==========================
  28. ;    INCLUDE "dh0:machinecode/assembler/devpac/system.GS"
  29.     INCDIR    "Include:"
  30.     include    "dos/dos.i"
  31.     include    "dos/datetime.i"
  32.     include    "exec/exec.i"
  33.     include    "LVO/exec_lib.i"
  34.     include    "LVO/dos_lib.i"
  35.     include    "MISC/XPK/xpk.i"
  36.     include "MISC/XPK/xpksub.i"
  37.  
  38. ;=========================  PROGRAM DEFINITIONS  ==========================
  39.  
  40. defaultcrypt    EQU    "IDEA"
  41. optioncrypt    EQU    "FEAL"
  42.  
  43. ;============================  STARTUP CODE  ==============================
  44.  
  45. start    lea        var(PC),a5
  46.  
  47.     movea.l        $4.w,a6
  48.     suba.l        a1,a1
  49.     CALLSYS    FindTask            ;Eigenen Task suchen
  50.     move.l        d0,a4
  51.     move.l        d0,my_task-var(a5)
  52.  
  53.     lea        $5c(a4),a1
  54.     move.l        a1,MSG_port-var(a5)    ;Get tasks MessagePort
  55.  
  56.     movea.l        $4.w,a6
  57.     lea        dosname-var(a5),a1
  58.     moveq        #34,d0
  59.     CALLSYS    OpenLibrary
  60.     move.l        d0,dosbase-var(a5)
  61.  
  62.     move.l        dosbase-var(a5),a6
  63.     CALLSYS    Output
  64.     move.l        d0,output_handle-var(a5)
  65.     beq.b    error_output
  66.  
  67.     move.l        $4.w,a0
  68.     cmp.w        #36,LIB_VERSION(a0)
  69.     blt.s    upgrade
  70.  
  71.     lea        xpkname-var(a5),a1
  72.     moveq        #0,d0
  73.     move.l        $4.w,a6
  74.     CALLSYS    OpenLibrary
  75.     move.l        d0,xpkbase-var(a5)
  76.     beq.b    error_output
  77.  
  78.     bsr.b    cli_parser
  79.     bne.b    not_opened
  80.  
  81.     lea        welcomemsg-var(a5),a0
  82.     move.l        a0,d2
  83.     moveq        #endwelcome-welcomemsg,d3
  84.     bsr.b    print_error
  85.  
  86.     bsr.w    create_tmp_filename
  87.     tst.l        d0
  88.     bne.b    not_opened            ;kein TMP-Filename gefunden
  89.     bsr.w    XPK_support
  90.     tst.l        d0
  91.     bne.b    not_opened            ;Fehler im XPK-Teil
  92.     bsr.w    copy_file            ;und file schreiben
  93.  
  94.     move.l        arguments-var(a5),d1
  95.     move.l        dosbase-var(a5),a6
  96.     CALLSYS    FreeArgs
  97.  
  98.  
  99. not_opened
  100.     move.l        $4.w,a6
  101.     move.l        xpkbase-var(a5),a1
  102.     CALLSYS    CloseLibrary
  103.  
  104. error_output
  105.     move.l        $4.w,a6
  106.     move.l        dosbase-var(a5),a1
  107.     CALLSYS    CloseLibrary
  108.  
  109. error_opening
  110.     moveq        #0,d0            ;keine Errorcodes
  111.     rts
  112.  
  113. upgrade    lea        upgrade_msg-var(a5),a0
  114.     move.l        a0,d2
  115.     moveq        #endupgrade-upgrade_msg,d3
  116.     bsr.b    do_print
  117.     bra.b    error_output
  118.  
  119. ;=========================================================================
  120. print_error
  121. ;
  122. ;    Uebergabeparameter :
  123. ;                d2 = Pointer auf auszugebenden Text
  124. ;                d3 = Laenge des auszugebenden Textes
  125. ;=========================================================================
  126.     lea        arg_array-var(a5),a0
  127.     tst.l        3*4(a0)            ;quiet flag testen
  128.     bne.b    quiet
  129. do_print
  130.     move.l        dosbase-var(a5),a6
  131.     move.l        output_handle-var(a5),d1
  132.     jmp    _LVOWrite(a6)
  133. quiet    rts
  134.  
  135. ;=========================================================================
  136. cli_parser
  137. ;
  138. ;    Uebergabeparameter :    keine
  139. ;
  140. ;    Rueckgabe :        d0 = -1 IF ERROR, 0 sonst
  141. ;=========================================================================
  142.     move.l        dosbase-var(a5),a6
  143.     lea        template-var(a5),a0
  144.     move.l        a0,d1
  145.     lea        arg_array-var(a5),a0
  146.     move.l        a0,d2
  147.     moveq        #0,d3            ;keine weitere Struktur
  148.     CALLSYS    ReadArgs
  149.     move.l        d0,arguments-var(a5)
  150.     beq.b    arg_error
  151.  
  152.     lea        arg_array-var(a5),a0    ;pointer auf Filename
  153.     move.l        (a0),d0
  154.     move.l        d0,input_1-var(a5)
  155.     move.l        d0,input_2-var(a5)    ;und in taglist
  156.     move.l        d0,filename-var(a5)
  157.  
  158.     moveq        #15-1,d0        ;15 Bytes max
  159.     lea        password-var(a5),a1    ;password umkopieren
  160.     move.l        8(a0),a0
  161. .loop    move.b        (a0)+,(a1)+
  162.     dbf    d0,.loop
  163.     moveq        #0,d0
  164.     rts
  165.  
  166. arg_error
  167.     lea        argerrormsg-var(a5),a0
  168.     move.l        a0,d2
  169.     moveq        #endmsg-argerrormsg,d3
  170.     bsr.b    do_print
  171.     moveq        #-1,d0
  172.     rts
  173.  
  174. ;=========================================================================
  175. create_tmp_filename
  176. ;
  177. ;    Uebergabeparameter :    keine
  178. ;
  179. ;    Rueckgabe :        d0 = -1 IF ERROR, 0 sonst
  180. ;=========================================================================
  181.     move.l        dosbase-var(a5),a6
  182.     lea        datearray-var(a5),a0
  183.     move.l        a0,d1
  184.     CALLSYS    DateStamp            ;Uhrzeit und Datum holen
  185.  
  186.     lea        datearray-var(a5),a0
  187.     move.l        a0,d1
  188.     CALLSYS    DateToStr            ;und in lesbaren String wandeln
  189.     tst.l        d0
  190.     beq.b    string_error
  191.  
  192.     lea        outputname-var(a5),a1    ;Uhrzeit zum Namen hinzufuegen
  193.     lea        time_string-var(a5),a0
  194.     moveq        #3-1,d0
  195. .copy    move.b        (a0)+,(a1)+
  196.     move.b        (a0)+,(a1)+
  197.     addq.l        #1,a0
  198.     dbf    d0,.copy
  199.  
  200.     moveq        #1,d0
  201. string_error
  202.     subq.l        #1,d0
  203.     rts
  204.  
  205. ;=========================================================================
  206. XPK_support
  207. ;    Uebergabeparameter :    keine
  208. ;
  209. ;    Rueckgabe :        d0 = -1 IF ERROR, 0 sonst
  210. ;=========================================================================
  211.     move.l        crypt1-var(a5),d0
  212.     move.l        crypt2-var(a5),d1
  213.     tst.l        arg_array+4-var(a5)
  214.     beq.b    .skip
  215.     move.l        d0,crypt2-var(a5)
  216.     move.l        d1,crypt1-var(a5)
  217.  
  218. .skip    lea        error_buffer-var(a5),a0    ;pointer auf XPK-Error-Buffer
  219.     move.l        a0,errorbuf-var(a5)    ;zum Ausgeben der Fehlermeldung
  220.  
  221.     move.l        xpkbase-var(a5),a6
  222.     lea        infostruct-var(a5),a0
  223.     lea        examine_tags-var(a5),a1
  224.     CALLSYS    XpkExamine            ;File anschauen, ob gecrypted
  225.     tst.l        d0
  226.     bne.b    error_xpkfunc
  227.  
  228.     lea        infostruct-var(a5),a0    ;hier stehen jetzt die infos
  229.     move.l        28(a0),d0        ;packer name
  230.  
  231.     cmp.l        crypt1-var(a5),d0    ;isset mit meinem Teil gecrypted?
  232.     beq.b    decrypt_file            ;ja : entcrypten
  233.  
  234.     cmp.l        crypt2-var(a5),d0    ;sonst gecrypted ? dann default
  235.     beq.b    decrypt_file            ;entcrypten
  236.  
  237.  
  238.     lea        pack_tags-var(a5),a0
  239.     CALLSYS    XpkPack
  240.     tst.l        d0
  241.     bne.b    error_xpkfunc
  242. no_error
  243.     rts
  244.  
  245. decrypt_file
  246.     lea        unpack_tags-var(a5),a0
  247.     CALLSYS    XpkUnpack
  248.     tst.l        d0
  249.     beq.b    no_error
  250.  
  251. error_xpkfunc
  252.     lea        error_buffer-var(a5),a0
  253.     move.l        a0,d2
  254.     move.b        #10,error_buffer+XPKERRMSGSIZE-var(a5)    ;Return
  255.     moveq        #XPKERRMSGSIZE+1,d3
  256.     bsr.w    print_error
  257.     moveq        #-1,d0
  258.     rts
  259.  
  260. ;=========================================================================
  261. copy_file
  262. ;
  263. ;    Uebergabeparameter :    keine
  264. ;
  265. ;    Rueckgabe :        keine
  266. ;=========================================================================
  267.     move.l        dosbase-var(a5),a6
  268.     move.l        arg_array-var(a5),d1        ;open inputfile
  269.     move.l        #MODE_NEWFILE,d2
  270.     CALLSYS    Open
  271.     move.l        d0,inputhandle-var(a5)
  272.     beq.b    error_opening_input
  273.  
  274.     lea        outputpath-var(a5),a0        ;open temporary file
  275.     move.l        a0,d1
  276.     move.l        #MODE_OLDFILE,d2
  277.     CALLSYS    Open
  278.     move.l        d0,temphandle-var(a5)
  279.     beq.b    error_opening_temp
  280.  
  281.     move.l        $4.w,a6
  282.     move.l        length-var(a5),d0        ;alloc mem for file
  283.     moveq        #MEMF_PUBLIC,d1
  284.     CALLSYS    AllocMem
  285.     move.l        d0,file_memory-var(a5)
  286.     beq.b    error_allocating
  287.  
  288.     move.l        dosbase-var(a5),a6
  289.     move.l        temphandle-var(a5),d1        ;Read temporary file
  290.     move.l        file_memory-var(a5),d2
  291.     move.l        length-var(a5),d3
  292.     CALLSYS    Read
  293.     beq.b    read_error
  294.  
  295.     move.l        inputhandle-var(a5),d1        ;Write input file
  296.     move.l        file_memory-var(a5),d2
  297.     move.l        length-var(a5),d3
  298.     CALLSYS    Write
  299.     tst.l        d0
  300.     beq.b    write_error
  301.     
  302. free_mem
  303.     move.l        $4.w,a6                ;Free memory
  304.     move.l        file_memory-var(a5),a1
  305.     move.l        length-var(a5),d0
  306.     CALLSYS    FreeMem
  307.  
  308. error_allocating
  309.     move.l        dosbase-var(a5),a6        ;Close temporary file
  310.     move.l        temphandle-var(a5),d1
  311.     CALLSYS    Close
  312. error_opening_temp
  313.     move.l        inputhandle-var(a5),d1        ;Close input file
  314.     CALLSYS    Close
  315. error_opening_input
  316.     lea        outputpath-var(a5),a0        ;Delete temporary file
  317.     move.l        a0,d1
  318.     CALLSYS    DeleteFile
  319.     rts
  320.  
  321. read_error
  322.     lea        readerrormsg-var(a5),a0
  323.     moveq        #endreadmsg-readerrormsg,d3
  324.     bra.b    skip    
  325. write_error
  326.     lea        writeerrormsg-var(a5),a0
  327. skip    moveq        #endwritemsg-writeerrormsg,d3
  328.     move.l        a0,d3
  329.     bsr.w    print_error
  330.  
  331.     bra.b    free_mem
  332.  
  333. ;==============================  VARIABLEN  ===============================
  334.         cnop    0,4
  335. ;==========================================================================
  336.         dc.b    0,"$VER:"
  337.         PRGNAME
  338.         VERSION
  339.         VersionDate
  340.         cnop    0,4
  341. ;==========================================================================
  342. var:
  343. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  344. dosbase        dc.l    0
  345. xpkbase        dc.l    0
  346. output_handle    dc.l    0
  347. arguments    dc.l    0
  348.  
  349. MSG_port    dc.l    0
  350. my_task        dc.l    0
  351. my_user_port    dc.l    0
  352.  
  353. inputhandle    dc.l    0
  354. temphandle    dc.l    0
  355. file_memory    dc.l    0
  356.  
  357. dosname        DOSNAME
  358.     cnop    0,2
  359. xpkname        XPKNAME
  360.  
  361.     cnop    0,4
  362.  
  363. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  364.  
  365. examine_tags    dc.l    XPK_InName
  366. filename    dc.l    0            ;spaeter durch CLI-Uebergabe
  367.         dc.l    XPK_GetError        ;pointer to the error message buffer
  368. errorbuf    dc.l    0
  369.         dc.l    TAG_DONE
  370.  
  371. pack_tags    dc.l    XPK_InName
  372. input_1        dc.l    0            ;hier pointer auf inputname
  373.         dc.l    XPK_GetError
  374.         dc.l    error_buffer
  375.         dc.l    XPK_OutName
  376.         dc.l    outputpath
  377.         dc.l    XPK_PackMethod
  378.         dc.l    crypt1
  379.         dc.l    XPK_PackMode
  380.         dc.l    100
  381.         dc.l    XPK_Password
  382.         dc.l    password
  383.         dc.l    XPK_GetOutLen
  384.         dc.l    length
  385.         dc.l    TAG_DONE
  386.  
  387. unpack_tags    dc.l    XPK_InName
  388. input_2        dc.l    0            ;hier pointer auf inputname
  389.         dc.l    XPK_GetError
  390.         dc.l    error_buffer
  391.         dc.l    XPK_OutName
  392.         dc.l    outputpath
  393.         dc.l    XPK_Password
  394.         dc.l    password
  395.         dc.l    XPK_GetOutLen
  396.         dc.l    length
  397.         dc.l    TAG_DONE
  398.  
  399. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  400.  
  401. length        dc.l    0            ;Filelaenge nach (de)crypten
  402.  
  403. crypt1        dc.l    defaultcrypt        ;hier schreibt der parser den
  404.         dc.w    0            ;gewaehlten cryptmode rein
  405.         dc.w    0            ;nur fuer LW-Align !!
  406. crypt2        dc.l    optioncrypt
  407.         dc.w    0
  408.         dc.w    0
  409.  
  410.  
  411. datearray    dcb.l    3            ;Struktur fuer DateStamp
  412.         dc.b    0            ;day of the week format
  413.         dc.b    FORMAT_DOS        ;date format dd-mmm-yy
  414.         dc.l    day_of_the_week
  415.         dc.l    date_string
  416.         dc.l    time_string
  417.  
  418. day_of_the_week    dcb.b    16
  419. date_string    dcb.b    16
  420. time_string    dcb.b    16
  421.  
  422.     even
  423. password    dcb.b    15            ;maximal 15 Zeichen !
  424.     even
  425. outputpath    dc.b    "T:XCrypt"
  426. outputname    dcb.b    6            ;Datum und Uhrzeit ..
  427.         dc.b    ".TMP",0
  428.  
  429.     even
  430. template    dc.b    "SOURCE/A,FEAL/S,PW/K/A,QUIET/S",0
  431.  
  432.     even
  433. arg_array    dcb.l    4            ;4 templates
  434. error_buffer    dcb.b    XPKERRMSGSIZE+1        ; +1 to make room for LF
  435.  
  436.     cnop 0,4
  437. infostruct    dcb.b    94            ;XpkExamine Info Struktur
  438.     cnop 0,4
  439.  
  440. ;================================  TEXTE  =================================
  441.  
  442. welcomemsg    dc.b    "Xcrypt Encrypter/Decrypter by Thorsten Hopf",10,0
  443. endwelcome
  444.     even
  445. upgrade_msg    dc.b    "After 3 years you should think about upgrading ..",10,0
  446. endupgrade
  447.     even
  448. argerrormsg    dc.b    "Error parsing arguments !",10,0
  449. endmsg
  450.     even
  451. readerrormsg    dc.b    "Error reading file",10,0
  452. endreadmsg
  453.     even
  454. writeerrormsg    dc.b    "Error writing file",10,0
  455. endwritemsg
  456. ;==========================================================================
  457. END
  458.